﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class Shop_TemplateFile_Edit : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            hType.Value = Shove._Web.Utility.GetRequest("Type");
            hID.Value = Shove._Web.Utility.GetRequest("ID");

            BindData();
        }
    }

    #region Web 窗体设计器生成的代码

    protected override void OnLoad(EventArgs e)
    {
        isRequestLogin = true;                                  //是否需要登录
        RequestLoginPage = this.Request.Url.AbsoluteUri;        //获取决对Url
        isAtFramePageLogin = true;                              //是框架页

        //RequestCompetences = Competences.BuildCompetencesList(Competences.);//页面权限

        base.OnLoad(e);
    }

    #endregion

    private void BindData()
    {
        long ID = Shove._Convert.StrToInt(hID.Value, 0);

        if (hType.Value == "Edit")
        {
            DataTable dt = new DAL.Tables.tbl_Site_TemplatesFile().Open("", "[ID]=" + ID, "");

            if (dt != null && dt.Rows.Count > 0)
            {
                lbFileName.Text = dt.Rows[0]["FileName"].ToString();
                lbRemark.Text = dt.Rows[0]["Remark"].ToString();
                tbLinks.Text = dt.Rows[0]["Links"].ToString();
                img1.Width = 400;   //System.Web.UI.WebControls.Unit
                img1.Height = 200;
                img1.ImageUrl = "../" + dt.Rows[0]["Directory"].ToString() + dt.Rows[0]["FileName"].ToString();
            }
        }
    }

    protected void btnOK_Click(object sender, EventArgs e)
    {
        btnOK.Enabled = false;
        long ID = Shove._Convert.StrToInt(hID.Value, 0);

        DAL.Tables.tbl_Site_TemplatesFile table = new DAL.Tables.tbl_Site_TemplatesFile();
        table.Links.Value = tbLinks.Text.Trim();

        DataTable dt = new DAL.Tables.tbl_Site_TemplatesFile().Open("", "[ID]=" + ID, "");

        if (this.File1.Value.Trim() != "")
        {
            string NewTypeName = "";

            if (Shove._IO.File.UploadFile(this.Page, File1, "../" + dt.Rows[0]["Directory"].ToString(), ref NewTypeName, true, "") < 0)
            {
                Shove._Web.JavaScript.Alert(this.Page, "图片上传失败！");
                return; 
            }

            table.FileName.Value = NewTypeName;                      
        }

        table.Update("ID=" + ID);  

        Shove._Web.JavaScript.Alert(this.Page, "更新成功！");       
    }

}